/** @file GUIController.h
*   @class GUIController
*    @brief The abstract parent class the MainMenuGUIController and InGameGUIController classes
*/
#include "stdafx.h"

#ifndef _GUIController_h_
#define _GUIController_h_

#include "Controller.h"
#include "Input.h"
#include <string>
#include <CEGUI/CEGUI.h>
#include <CEGUI/RendererModules/Ogre/CEGUIOgreRenderer.h>
#include "InputObserver.h"

using namespace std;

class GUIController : public Controller, public InputObserver {
public:
	GUIController(Model *model, Ogre::RenderWindow* window, string scheme);
	virtual ~GUIController();
	virtual bool update(float deltaTime);

	/**
	* @brief Sets the GUI sheet (layout) to be used
	*/
	void setGUIsheet(string layoutName);
	
protected:
	CEGUI::Window *m_sheet;
	string m_scheme;

	/*
	*  @brief Injects key event for keyboard key pressedinto CEGUI
	*  
	*  True when key KeyEvent has been pressed. Injects key events into the CEGUI system in order to catch when keys are pressed
	*/
	bool keyPressed(const OIS::KeyEvent &arg);

	/*
	*  @brief Injects key event for keyboard key released into CEGUI
	*  
	*  True when key KeyEvent has been released. Injects key events into the CEGUI system in order to catch when keys are released
	*/
	bool keyReleased(const OIS::KeyEvent &arg);
	
	/** 
	*  @brief For injecting mouse moved events into CEGUI
	*
	*	True when mouse has been moved from the last update. Injects mouse moved events into the CEGUI system, so mouse cursor in menus etc can be updated
	*/
	bool mouseMoved( const OIS::MouseEvent &arg );
	
	/** 
	*  @brief  For injecting mouse button down events into CEGUI
	*	
	*	True when mousebutton MouseButtonID has been pressed. Injects mouse button down events into the CEGUI system, so mouse clicks can be registered. Requires converting the button ID with the convertButton Method
	*/
	bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id );

	/** 
	*  @brief For injecting mouse button up events into CEGUI
	*
	*  True when mousebutton MouseButtonID has been released. Injects mouse button up events into the CEGUI system, so mouse releases can be registered.  Requires converting the button ID with the convertButton Method
	*/
	bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id );

	/**
	*  @brief Injects timestamps into CEGUI system so that it can be updated
	*/
	void updateGUI(float deltaTime);

	static CEGUI::OgreRenderer* m_Renderer;

	/**
	* @Brief Does the necessary steps to initialize the GUI
	*
	* Bootstraps the CEGUI system, set the default resource groups for the CEGUI resource managers
	* selects the skin and sets the mouse cursor
	*/
	void initializeCEGUI(string scheme);

	/**
	* @brief Converts from OIS mouse button IDs to CEGUI mouse button IDs
	*
	* OIS::MB_Left = CEGUI::LeftButton
	* OIS::MB_Right = CEGUI::RightButton
	* OIS::MB_Middle = CEGUI::MiddleButton
	* Per default left button click is returned
	*/
    CEGUI::MouseButton convertButton(OIS::MouseButtonID buttonID);

	static bool m_isInitialized;

};

#endif
